package com.cqhfan.imservice.config;

import com.cqhfan.imservice.handler.ImConnectionHandler;
import com.cqhfan.imservice.interceptors.CustomHandshakeInterceptor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @author 眭传洪
 * @create 2025-08-16 1:50
 */
@Slf4j
@Configuration
@RequiredArgsConstructor
public class WebSocketConfig implements WebSocketConfigurer {

    private final ImConnectionHandler handler;

    private final CustomHandshakeInterceptor customHandshakeInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(handler, "/ws/chat/{accessToken}")
                .addInterceptors(customHandshakeInterceptor)
                .setAllowedOrigins("*");
        log.info("websocket初始化成功。。。");
    }

}
